package com.finger.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.finger.gulimall.order.config.AlipayTemplate;
import com.finger.gulimall.order.entity.vo.PayVo;
import com.finger.gulimall.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName PayWebController
 * @Description
 * @Author finger
 * @Date 2023/4/30 15:27
 * @Version 1.0
 */

@Controller
public class PayWebController {

	@Autowired
	AlipayTemplate alipayTemplate;

	@Autowired
	OrderService orderService;

	@ResponseBody
	@GetMapping(value = "/payOrder",produces = "text/html")
	public String payOrder(@RequestParam("orderSn")String orderSn) throws AlipayApiException {

		PayVo payVo = new PayVo();
		payVo.setOut_trade_no(orderSn);
		orderService.getPayOrder(payVo);
		return alipayTemplate.pay(payVo);
	}

}
